<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<head>
	<title>Projeto [listagem]</title>
</head>
<body>
	<jsp:include page="/WEB-INF/jsp/menu.jsp"></jsp:include>
	
	<c:set var="EM_ELABORACAO" value="<%=br.com.puc.models.enums.StatusProjeto.EM_ELABORACAO%>"/>
	<c:set var="EM_ANDAMENTO" value="<%=br.com.puc.models.enums.StatusProjeto.EM_ANDAMENTO%>"/>
	<c:set var="CONCLUIDO" value="<%=br.com.puc.models.enums.StatusProjeto.CONCLUIDO%>"/>
	
	<c:if test="${not empty mensagem}">		
		<h4>${mensagem}</h4>
	</c:if>

	<h1>Projetos em Elaboração</h1>
	<table>
		<tr>
			<th>Titulo</th>
			<th>Data inicio</th>
			<th>Data termino</th>
			<th></th>
			<c:if test="${ sessaoUsuario.logado }">			
				<th></th>
				<th></th>
				<th></th>			
			</c:if>
		</tr>

		<c:forEach items="${projetoList}" var="projeto">
			<c:if test="${ projeto.status == EM_ELABORACAO }">			
				<tr>
					<td>${projeto.titulo}</td>
					<td>${projeto.dataInicioStr}</td>
					<td>${projeto.dataTerminoStr}</td>
					<td><a href="${pageContext.request.contextPath}/projetos/${projeto.id}">mostrar</a></td>
					<c:if test="${ sessaoUsuario.logado }">
						<td><a href="${pageContext.request.contextPath}/projetos/${projeto.id}/edit">editar</a></td>
						<td>
							<form action="${pageContext.request.contextPath}/projetos/iniciar/${projeto.id}" method="post">
								<button type="submit" onclick="return confirm('Tem certeza?')">iniciar projeto</button>
							</form>
						</td>
						<td>
							<form action="${pageContext.request.contextPath}/projetos/${projeto.id}" method="post">
								<input type="hidden" name="_method" value="delete"/>
								<button type="submit" onclick="return confirm('Tem certeza?')">excluir</button>
							</form>
						</td>
					</c:if>
				</tr>
			</c:if>
		</c:forEach>
	</table>
	
	<h1>Projetos em Andamento</h1>
	<table>
		<tr>
			<th>Titulo</th>
			<th>Data inicio</th>
			<th>Data termino</th>			
			<th></th>
			<c:if test="${ sessaoUsuario.logado }">			
				<th></th>
				<th></th>
				<th></th>
			</c:if>
		</tr>

		<c:forEach items="${projetoList}" var="projeto">
			<c:if test="${ projeto.status == EM_ANDAMENTO }">			
				<tr>
					<td>${projeto.titulo}</td>
					<td>${projeto.dataInicioStr}</td>
					<td>${projeto.dataTerminoStr}</td>
					<td><a href="${pageContext.request.contextPath}/projetos/${projeto.id}">mostrar</a></td>
					<c:if test="${ sessaoUsuario.logado }">
						<td><a href="${pageContext.request.contextPath}/projetos/${projeto.id}/edit">editar</a></td>
						<td>
							<form action="${pageContext.request.contextPath}/projetos/concluir/${projeto.id}" method="post">
								<button type="submit" onclick="return confirm('Tem certeza?')">concluir projeto</button>
							</form>
						</td>
						<td>
							<form action="${pageContext.request.contextPath}/projetos/${projeto.id}" method="post">
								<input type="hidden" name="_method" value="delete"/>
								<button type="submit" onclick="return confirm('Tem certeza?')">excluir</button>
							</form>
						</td>
					</c:if>
				</tr>
			</c:if>
		</c:forEach>
	</table>
	
	<h1>Projetos Concluídos</h1>
	<table>
		<tr>
			<th>Titulo</th>
			<th>Data inicio</th>
			<th>Data termino</th>
			<th></th>
		</tr>

		<c:forEach items="${projetoList}" var="projeto">
			<c:if test="${ projeto.status == CONCLUIDO }">			
				<tr>
					<td>${projeto.titulo}</td>
					<td>${projeto.dataInicioStr}</td>
					<td>${projeto.dataTerminoStr}</td>
					<td><a href="${pageContext.request.contextPath}/projetos/${projeto.id}">mostrar</a></td>					
				</tr>
			</c:if>
		</c:forEach>
	</table>

	<br />
	<c:if test="${ sessaoUsuario.logado }">
		<a href="${pageContext.request.contextPath}/projetos/new">Novo Projeto</a>
	</c:if> 
</body>